// ScheduleLog.cpp: implementation of the CScheduleLog class.
//
//////////////////////////////////////////////////////////////////////

#include "ScheduleLog.h"
#include "XMLConfig2.h"

#ifdef __linux__
	#include <stdarg.h>
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#define FPRINT_STRING(fp, str) { \
fprintf(fp, "%-10s ", str); }


void (*glbLogger)(UInt8 nLogType, UInt8 nLogPri, char *szLogInfo);


void OutputLogInfo(UInt8 nLogType, UInt8 nLogPri, char *szLogInfo, ...)
{
    va_list         arglist;
    char szTmp[4096];
    va_start(arglist,szLogInfo);
    vsprintf(szTmp,szLogInfo,arglist);
    va_end(arglist);

	if(glbLogger != NULL){
		glbLogger(nLogType, nLogPri, szTmp);
	}
}

int CScheduleLog::SetItems(const char *szDesc)
{	
	m_strDesc = szDesc;	
	return LOG_SUCCESS;
}

int CScheduleLog::MakeDir()
{
	ResetPath();	
	SetPath( SConfigPara::m_LogDir );
	SetPath("log");
	SetPath("sch");
	
	return CLog::MakeDir();
}
int CScheduleLog::WriteHeader()
{
	if(LOG_SUCCESS != CLog::WriteHeader())
		return LOG_FAIL;

	fprintf(m_fpLogFile, "#Log Type: Schedule Log\n"); 
	fprintf(m_fpLogFile, "#Fields: \n");

	FPRINT_STRING(m_fpLogFile, "#x-seq");
	FPRINT_STRING(m_fpLogFile, "date");
	FPRINT_STRING(m_fpLogFile, "time");	
	FPRINT_STRING(m_fpLogFile, "log information");	

	fprintf(m_fpLogFile, "\n");
	
	return LOG_SUCCESS;

}
int CScheduleLog::WriteItems()
{
	if(m_nStatus == 1 || m_nStatus == 3)
	{
		fprintf(m_fpLogFile, " %s", m_strDesc.c_str());
	}
	
	if(m_nStatus == 2 || m_nStatus == 3)
	{
		printf("Sch_Log: %s", m_strDesc.c_str());
	}

	return LOG_SUCCESS;
}
